package me.samlss.lighter_demo.slice;

import me.samlss.lighter.Lighter;
import me.samlss.lighter.interfaces.OnLighterListener;
import me.samlss.lighter.parameter.Direction;
import me.samlss.lighter.parameter.LighterParameter;
import me.samlss.lighter.parameter.MarginOffset;
import me.samlss.lighter.shape.CircleShape;
import me.samlss.lighter.shape.OvalShape;
import me.samlss.lighter.shape.RectShape;
import me.samlss.lighter_demo.LighterHelper;
import me.samlss.lighter_demo.ResourceTable;
import me.samlss.lighter_demo.tools.Toast;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.DependentLayout;
/**
 * @author: zhu_zhonglin
 * @time: 2021/4/25
 */
public class RelativeLayoutAbilitySlice extends AbilitySlice {
    private DependentLayout rootView;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_relative_layout);
        initView();
        showGuide();
    }

    private void initView() {
        rootView = (DependentLayout) findComponentById(ResourceTable.Id_root);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    private void showGuide() {

        CircleShape circleShape = new CircleShape(25);
        circleShape.setPaint(LighterHelper.getDashPaint());

        RectShape rectShape = new RectShape();
        rectShape.setPaint(LighterHelper.getDiscretePaint());

        Lighter lighter = Lighter.with(rootView);
        lighter.setBackgroundColor(0x000000, 0.5f)
                .setOnLighterListener(new OnLighterListener() {
                    @Override
                    public void onShow(int index) {
//                        Toast.show(getApplicationContext(), "正在显示第" + (index + 1) + "高亮", Toast.LENGTH_SHORT);
                    }

                    @Override
                    public void onDismiss() {
                        Toast.show(getApplicationContext(), "高亮已全部显示完毕", Toast.LENGTH_SHORT);
                    }
                })
                .addHighlight(new LighterParameter.Builder()
                        .setHighlightedViewId(ResourceTable.Id_iv_head_photo)
                        .setTipLayoutId(ResourceTable.Layout_layout_tip_1)
                        .setLighterShape(circleShape)
                        .setTipViewRelativeDirection(Direction.RIGHT)
                        .setTipViewDisplayAnimation(LighterHelper.getScaleAnimation())
                        .setTipViewRelativeOffset(new MarginOffset(30, 0, 80, 0))
                        .build())
                .addHighlight(new LighterParameter.Builder()
                        .setHighlightedViewId(ResourceTable.Id_layout_balance)
                        .setTipLayoutId(ResourceTable.Layout_layout_tip_2)
                        .setLighterShape(rectShape)
                        .setTipViewRelativeDirection(Direction.TOP)
                        .setShapeXOffset(10)
                        .setShapeYOffset(10)
                        .setTipViewDisplayAnimation(LighterHelper.getTranslateAnimation())
                        .setTipViewRelativeOffset(new MarginOffset(0, 10, 0, 20))
                        .build())
                .addHighlight(new LighterParameter.Builder()
                        .setHighlightedViewId(ResourceTable.Id_btn_highlight2)
                        .setTipView(LighterHelper.createCommonTipView(getAbility(), ResourceTable.Media_icon_tip_4, "向左移动", lighter.getInternalImpl().getLighterView()))
                        .setLighterShape(rectShape)
                        .setTipViewRelativeDirection(Direction.LEFT)
                        .setTipViewDisplayAnimation(LighterHelper.getScaleAnimation())
                        .setTipViewRelativeOffset(new MarginOffset(0, 20, 0, 0))
                        .build())
                .addHighlight(new LighterParameter.Builder()
                                .setHighlightedViewId(ResourceTable.Id_btn_highlight1)
                                .setTipLayoutId(ResourceTable.Layout_layout_tip_3)
                                .setLighterShape(new RectShape(0, 0, 25))
                                .setTipViewRelativeDirection(Direction.TOP)
                                .setTipViewDisplayAnimation(LighterHelper.getScaleAnimation())
                                .setTipViewRelativeOffset(new MarginOffset(100, 10, 0, 20))
                                .build(),
                        new LighterParameter.Builder()
                                .setHighlightedViewId(ResourceTable.Id_btn_highlight3)
                                .setTipLayoutId(ResourceTable.Layout_layout_tip_1)
                                .setLighterShape(new OvalShape())
                                .setTipViewRelativeDirection(Direction.BOTTOM)
                                .setTipViewDisplayAnimation(LighterHelper.getScaleAnimation())
                                .setTipViewRelativeOffset(new MarginOffset(300, 0, 0, 0))
                                .build())
                .show();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
